from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


# https://www.django-rest-framework.org/api-guide/pagination/
# 把文章列表，总页码和文章总数返回给前端
class BasePagination(PageNumberPagination):
    """自定制分页"""
    page_size = 5

    def get_paginated_response(self, data):
        return Response({
            'num_pages': self.page.paginator.num_pages,
            'count': self.page.paginator.count,
            'results': data
        })


class HomePagePagination(BasePagination):
    page_size = 8


class PostsPagination(BasePagination):
    page_size = 12
